#include <shmem.h>

#define N 4
static struct shm_param para;

struct student
{
    int num;
    char name[64];
};

int main(int argc, char *argv[])
{
    int ret = -1;
    int *num = NULL;
    void *a = NULL;
    struct student *stuaddr = NULL;
    ret = shm_init(&para, "shm_testq", sizeof(struct student)*N+4);
    if(ret < 0)
    {
        return -1;
    }
    para.size = sizeof(struct student)*N+4;
    a = shm_getaddr(&para);
    num = (int*) a;
    if(num == NULL)
    {
        return -1;
    }
    stuaddr = num + sizeof(int);
    if(stuaddr == NULL)
    {
        return -1;
    }
    *num = 4;
    stuaddr[0].num = 160;
    strcpy(stuaddr[0].name, "zhangsan");
    stuaddr[1].num = 165;
    strcpy(stuaddr[1].name, "lisi");
    stuaddr[2].num = 170;
    strcpy(stuaddr[2].name, "wangwu");
    stuaddr[3].num = 175;
    strcpy(stuaddr[3].name, "ermazi");
    shm_write(&para, num, sizeof(struct student)*N+4);

    return 0;
}
